<template>
  <div id="cluereport">
    <el-dialog
      :title="dialogtitle"
      :visible.sync="dialogVisible"
      width="98%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <personEdit @dialogHide="dialogHide($event)" :theYear="theYear" :personId="personId" :readOnly="readonly" :timestamp="timestamp" :showDept="true" :Formal="true"></personEdit>
    </el-dialog>
    <el-dialog
      title="统计分析"
      :visible.sync="webDataDialogVisible"
      width="98%" :close-on-click-modal="false" :close-on-press-escape="false">
      <webData @dialogHide="dialogHide2()" :url="dataUrl" :para="dataPara"  :timestamp="timestamp" toolbar></webData>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <!-- <el-breadcrumb-item>人才建设</el-breadcrumb-item> -->
      <el-breadcrumb-item :to="{ path: '/youngCadres/yearlist' }">优秀年轻干部</el-breadcrumb-item>
      <el-breadcrumb-item>{{ theYear + '年' }}</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
      <h1>优秀年轻干部</h1>
      <el-form :inline="true" :model="filters">
        <div style="padding:22px 22px 0;">
          <el-radio-group v-model="showType" @change="changetype">
            <el-radio-button label="候选库" border>
            </el-radio-button>
            <el-radio-button label="正式库" border>
            </el-radio-button>
          </el-radio-group>
          <el-form-item label="所属处室" label-width="90px" v-if="inRoles('ROLE_sizhang')||inRoles('ROLE_admin')">
            <el-select v-model="filters.sscs" placeholder="请选择" style="width:120px;">
              <el-option label="全部" value=""></el-option>
              <el-option label="干部一处" value="1"></el-option>
              <el-option label="干部二处" value="2"></el-option>
              <el-option label="干部三处" value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属处室" label-width="90px" v-else-if="inRoles('ROLE_fusizhang')&&sscsArr&&sscsArr.length>1">
            <el-select v-model="filters.sscs" placeholder="请选择" style="width:120px;">
              <el-option label="全部" value=""></el-option>
              <el-option label="干部一处" value="1" v-if="sscsArr.indexOf(1)>-1"></el-option>
              <el-option label="干部二处" value="2" v-if="sscsArr.indexOf(2)>-1"></el-option>
              <el-option label="干部三处" value="3" v-if="sscsArr.indexOf(3)>-1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属处室" label-width="90px" v-else-if="inRoles('ROLE_fusizhang')&&sscsArr.length===0">
            <el-select v-model="filters.sscs" placeholder="请选择" style="width:120px;">
              <el-option label="全部" value=""></el-option>
              <el-option label="干部一处" value="1"></el-option>
              <el-option label="干部二处" value="2"></el-option>
              <el-option label="干部三处" value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单位名称" label-width="90px">
            <!-- <el-input v-model="filters.dwmc" style="width:200px;" placeholder="关键字"></el-input> -->
            <el-autocomplete style="width:200px" v-model="filters.dwmc" :fetch-suggestions="searchUnit" placeholder="关键字" :trigger-on-focus="false">
            </el-autocomplete>
          </el-form-item>
          <el-form-item label="姓名" label-width="50px">
            <el-input v-model="filters.xm" style="width:100px;" placeholder="关键字"></el-input>
          </el-form-item>
          <el-form-item label="身份证号" label-width="90px" v-if="moreShow">
            <el-input v-model="filters.sfzh" style="width:180px;"></el-input>
          </el-form-item>
          <el-form-item label="年龄" label-width="50px" v-if="moreShow">
            <el-input-number v-model="filters.qsnl" style="width:100px;" :min="0" :max="100" controls-position="right"></el-input-number> 至
            <el-input-number v-model="filters.zznl" style="width:100px;" :min="0" :max="100" controls-position="right"></el-input-number>
          </el-form-item>
          <el-form-item label="性别" label-width="50px" v-if="moreShow">
            <el-select v-model="filters.xb" placeholder="请选择" style="width:80px;">
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="item in xboptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <div style="clear:both" v-if="moreShow"></div>
          <el-form-item label="状态" label-width="50px">
            <el-select v-model="filters.zt" placeholder="请选择" style="width:100px;">
              <el-option label="正常" :value="0"></el-option>
              <el-option label="已出库" :value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="职务职级层次" label-width="110px" v-if="moreShow">
            <el-select v-model="filters.shfl" placeholder="请选择" style="width:160px;">
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="item in shfloptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="来源类型" label-width="80px" v-if="moreShow">
            <el-select v-model="filters.lyfl" placeholder="请选择" style="width:160px;">
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="item in lyfloptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="培养使用建议类型" label-width="150px" v-if="moreShow">
            <el-select v-model="filters.pysyjylx" placeholder="请选择" style="width:160px;">
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="item in pysyjylxoptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="超出年龄范围" label-width="120px" v-if="moreShow">
            <el-select v-model="filters.isOverAge" placeholder="请选择" style="width:80px;">
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="item in nloptions"
                :key="'nl' + item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" circle @click="search" icon="el-icon-search"></el-button>
            <el-tooltip class="item" effect="dark" content="统计分析" placement="top">
              <el-button circle type="success" @click="showWebData" icon="el-icon-data-line"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" :content="moreShow?'隐藏更多':'展开更多'" placement="top">
              <el-button circle @click="changeMoreShow()" :type="moreShow?'info':''" icon="el-icon-more" :style="moreShow?'':'color:#000 !important'"></el-button>
            </el-tooltip>
          </el-form-item>
          <el-form-item style="float:right;" v-if="canedit">
            <el-button-group v-if="setOrderFlag&&this.ids&&this.ids.length>0">
              <el-tooltip class="item" effect="dark" content="上移" placement="top">
                <el-button @click="setOrder(1)" icon="el-icon-arrow-up" type="danger" :loading="orderloading" :disabled="this.ids.length>0&&this.list.length&&this.ids[0]===this.list[0].id&&pageNum===1"></el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="下移" placement="top">
                <el-button @click="setOrder(2)" icon="el-icon-arrow-down" type="danger" :loading="orderloading" :disabled="this.ids.length>0&&this.list.length&&this.ids[0]===this.list[this.list.length-1].id&&pageNum===parseInt(totalPage)"></el-button>
              </el-tooltip>
            </el-button-group>
            <el-tooltip class="item" effect="dark" content="查看日志" placement="top" v-if="inRoles('ROLE_youngadmin')">
              <el-button circle type="info" @click="showlog" icon="el-icon-edit"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="新增" placement="top">
              <el-button circle type="success" @click="addnew" icon="el-icon-circle-plus-outline"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="批量出库" placement="top">
              <el-button circle type="danger" @click="del()" icon="el-icon-delete"></el-button>
            </el-tooltip>
          </el-form-item>
        </div>
      </el-form>
    </section>
    <section class="wboxd" style="margin-top:10px">
      <!--列表-->
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" @sort-change='sortChange' :height="tableHeight" border
        @selection-change="handleSelectionChange"
        ref="multipleTable" v-if="canedit"
        >
        <el-table-column type="index" label="序号" width="50" fixed align="center" class-name="tableth" :index="indexMethod">
        </el-table-column>
        <el-table-column type="selection" width="45" fixed v-if="canedit">
        </el-table-column>
        <el-table-column prop="dwmc" label="单位" sortable="custom" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="xm" label="姓名" width="80" align="center" sortable="custom" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="nl" width="100" align="center" sortable="custom" show-overflow-tooltip>
          <template slot="header" slot-scope="scope">
            <span>年龄</span>
            <el-tooltip class="item" effect="dark" content="按当前日期减去身份证号中出生日期自动计算" placement="top">
              <el-button style="color: #000 !important;" type="text" icon="el-icon-info" />
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="sfzh" label="身份证号" width="150" align="center" sortable="custom" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="isOverAge" label="超出年龄范围" width="140" align="center" sortable="custom" show-overflow-tooltip>
          <template slot-scope="scope">
            <span :class="{'red-bold': scope.row.isOverAge === 1}">
              {{ scope.row.isOverAge === 1 ? '是' : scope.row.isOverAge === 2 ?'否' : '' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="shfl" label="职务职级层次" width="140" align="center" show-overflow-tooltip sortable="custom">
          <template slot-scope="scope">
            {{scope.row.shflText}}
          </template>
        </el-table-column>
        <el-table-column prop="lyfl" label="来源类型" width="120" align="center" show-overflow-tooltip sortable="custom">
          <template slot-scope="scope">
            {{scope.row.lyflText}}
          </template>
        </el-table-column>
        <el-table-column prop="pysyjylx" label="培养使用建议类型" width="170" align="center" show-overflow-tooltip sortable="custom">
          <template slot-scope="scope">
            {{scope.row.pysyjylxText}}
          </template>
        </el-table-column>
        <el-table-column prop="rksj" label="入库时间" width="120" align="center" show-overflow-tooltip sortable="custom">
        </el-table-column>
        <el-table-column prop="cksj" label="出库时间" width="120" align="center" show-overflow-tooltip sortable="custom">
        </el-table-column>
        <el-table-column label="操作" width="250" align="center">
          <template slot-scope="scope">
            <el-button @click="detail(scope.row.id)" size="mini" style="color:#000 !important;margin:10px 0 10px 5px">查看</el-button>
            <el-button v-if="!showCksj" @click="edit(scope.row.id)" type="primary" size="mini" style="margin:10px 0 10px 5px">编辑</el-button>
            <el-button v-if="!showCksj" @click="del(scope.row.id)" type="danger" size="mini" style="margin:10px 0 10px 5px">出库</el-button>
            <el-button v-if="showCksj" @click="reEnter(scope.row.id)" type="success" size="mini" style="margin:10px 0 10px 5px">入库</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" @sort-change='sortChange' :height="tableHeight" border
        ref="multipleTable" v-else
        >
        <el-table-column type="index" label="序号" width="50" fixed align="center" class-name="tableth">
        </el-table-column>
        <el-table-column type="selection" width="45" fixed v-if="canedit">
        </el-table-column>
        <el-table-column prop="dwmc" label="单位" sortable="custom" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="xm" label="姓名" width="80" align="center" sortable="custom" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="nl" width="100" align="center" sortable="custom" show-overflow-tooltip>
          <template slot="header" slot-scope="scope">
            <span>年龄</span>
            <el-tooltip class="item" effect="dark" content="按当前日期减去身份证号中出生日期自动计算" placement="top">
              <el-button style="color: #000 !important;" type="text" icon="el-icon-info" />
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="sfzh" label="身份证号" width="150" align="center" sortable="custom" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="isOverAge" label="超出年龄范围" width="140" align="center" sortable="custom" show-overflow-tooltip>
          <template slot-scope="scope">
            <span :class="{'red-bold': scope.row.isOverAge === 1}">
              {{ scope.row.isOverAge === 1 ? '是' : scope.row.isOverAge === 2 ?'否' : '' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="shfl" label="职务职级层次" width="140" align="center" show-overflow-tooltip sortable="custom">
          <template slot-scope="scope">
            {{scope.row.shflText}}
          </template>
        </el-table-column>
        <el-table-column prop="lyfl" label="来源类型" width="120" align="center" show-overflow-tooltip sortable="custom">
          <template slot-scope="scope">
            {{scope.row.lyflText}}
          </template>
        </el-table-column>
        <el-table-column prop="pysyjylx" label="培养使用建议类型" width="170" align="center" show-overflow-tooltip sortable="custom">
          <template slot-scope="scope">
            {{scope.row.pysyjylxText}}
          </template>
        </el-table-column>
        <el-table-column prop="rksj" label="入库时间" width="120" align="center" show-overflow-tooltip sortable="custom">
        </el-table-column>
        <el-table-column prop="cksj" label="出库时间" width="120" align="center" show-overflow-tooltip sortable="custom">
        </el-table-column>
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button @click="detail(scope.row.id)" type="primary" size="mini" style="margin:10px 0 10px 5px">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination style="float:right" :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
import personEdit from './edit'
import webData from '../components/webData'
export default {
  components: {
    personEdit,
    webData
  },
  data () {
    return {
      webDataDialogVisible: false,
      dataUrl: this.$http.defaults.youngAPI + `api/busFormalPerson/queryAll`,
      dataPara: {},
      xboptions: [],
      shfloptions: [],
      lyfloptions: [],
      pysyjylxoptions: [],
      showCksj: false,
      canedit: false,
      showType: '正式库',
      moreShow: false,
      exportLoading1: false,
      cllxDic: [],
      wtlyDic: [],
      cljdjgDic: [],
      yxqDic: [],
      roleAdmin: true,
      roleEdit: true,
      roleChart: true,
      settype: '',
      setAuthText: '',
      roleSubmitLoading2: false,
      isIndeterminate2: false,
      roleSubmitLoading: false,
      role: [],
      checkAll2: false,
      checkAll: false,
      isIndeterminate: false,
      setRole: false,
      setrole0: false,
      // roles: [{label: '查看', value: 1}, {label: '编辑', value: 2}, {label: '分析', value: 3}],
      roles: ['查看', '编辑', '分析'],
      roles2: [],
      roleuser: [],
      userlist: [],
      processId: '',
      drawer: false,
      authUser: '',
      timestamp: '',
      noRoleCode: '***',
      noRoleText: '***',
      filters: {
        sscs: null,
        dwmc: '',
        sfzh: '',
        xb: '',
        xm: '',
        zt: 0,
        isOverAge: ''
      },
      listLoading: false,
      ids: [],
      tableHeight: 100,
      list: [
      ],
      pageNum: 1,
      pageSize: 20,
      totalnum: 10,
      personId: 0,
      dialogtitle: '新增',
      dialogVisible: false,
      readonly: false,
      total: 0,
      Isace: 'asc',
      Sortkey: '',
      changeSizeFlag: false,
      myloading: false,
      userRoles: '',
      sscsArr: [],
      totalPage: 0,
      setOrderFlag: true,
      orderloading: false,
      nloptions: [
        {
          label: '是',
          value: 1
        },
        {
          label: '否',
          value: 2
        }
      ],
      theYear: ''
    }
  },
  methods: {
    showWebData () {
      this.$router.push({name: 'youngCadresAnalyse', params: {theYear: this.theYear}})
      // this.dataPara = {
      //   xm: this.filters.xm,
      //   dwmc: this.filters.dwmc,
      //   qsnl: this.moreShow ? this.filters.qsnl : null,
      //   zznl: this.moreShow ? this.filters.zznl : null,
      //   sfzh: this.moreShow ? this.filters.sfzh : null,
      //   xb: this.moreShow ? this.filters.xb : null,
      //   zt: this.filters.zt,
      //   shfl: this.moreShow ? this.filters.shfl : null,
      //   lyfl: this.moreShow ? this.filters.lyfl : null,
      //   pysyjylx: this.moreShow ? this.filters.pysyjylx : null,
      //   sscs: this.filters.sscs ? [this.filters.sscs] : this.sscsArr
      // }
      // this.webDataDialogVisible = true
      // this.timestamp = new Date().getTime()
    },
    setOrder (direction) {
      if (this.ids && this.ids.length === 1) {
        let para = {personId: this.ids[0], direction: direction}
        this.orderloading = true
        this.$http
          .post(this.$http.defaults.youngAPI + 'api/busFormalPerson/updateOrder', para)
          .then(response => {
            this.orderloading = false
            if (response.data.success) {
              this.getList(this.ids[0])
            } else {
              let errormsg = ''
              if (response.data.code === 10) {
                errormsg = '您要调整排序的人员已经是该人员所在单位第一位，无法向上调整排序'
              } else if (response.data.code === 11) {
                errormsg = '您要调整排序的人员已经是该人员所在单位最后一位，无法向下调整排序'
              }
              this.$message({
                message: '调整排序失败:' + errormsg,
                type: 'error'
              })
            }
          })
          .catch(error => {
            this.orderloading = false
            console.log(error)
            this.$message({
              message: '网络排序失败:' + error,
              type: 'error'
            })
          })
      } else {
        this.$message({
          message: '请选择一条信息进行排序',
          type: 'error'
        })
      }
    },
    indexMethod (index) {
      return index + (this.pageNum - 1) * this.pageSize + 1
    },
    showlog () {
      this.$router.push({name: 'youngCadresLog', params: {theYear: this.theYear}})
    },
    changeMoreShow () {
      this.moreShow = !this.moreShow
      this.tableresize(this)
    },
    inRoles (str) {
      let arr = this.userRoles
      if (arr.indexOf(str) === -1) {
        return false
      } else {
        return true
      }
    },
    checkyoungCadresRole () {
      if (this.inRoles('ROLE_other')) {
        this.$router.push({name: 'youngCadresDept'})
        this.getList()
      } else if (this.inRoles('ROLE_sizhang') || this.inRoles('ROLE_youngadmin')) {
        this.canedit = true
        this.sscsArr = null
        this.getList()
      } else if (this.inRoles('ROLE_admin')) {
        this.canedit = false
        this.sscsArr = null
        this.getList()
      } else if (this.inRoles('ROLE_fusizhang')) {
        this.canedit = true
        this.$http
          .get(this.$http.defaults.youngAPI + `api/young/security/getCurrentManageDep`)
          .then(response => {
            if (response.data.success) {
              // if (response.data.result && response.data.result.length > 0) {
              this.sscsArr = response.data.result
              this.getList()
              // }
            } else {
              this.$message({
                message: '获取失败:' + response.data.message,
                type: 'error'
              })
            }
          })
          .catch(error => {
            if (error.status === 500) {
              this.$message({
                message: '网络获取失败:' + error,
                type: 'error'
              })
            }
          })
      } else if (this.inRoles('ROLE_banshirenyuan')) {
        this.canedit = false
        // this.$router.push({name: 'youngCadresDeptList'})
        this.getList()
      } else if (this.inRoles('ROLE_chuzhang')) {
        this.canedit = true
        switch (localStorage.getItem('unitName')) {
          case '干部一处':
            this.sscsArr = [1]
            break
          case '干部二处':
            this.sscsArr = [2]
            break
          case '干部三处':
            this.sscsArr = [3]
            break
        }
        this.getList()
      }
    },
    changetype () {
      if (this.showType === '候选库') {
        this.$router.push({name: 'youngCadresDeptList', query: {theYear: this.theYear}})
      } else if (this.showType === '正式库') {
        this.$router.push({name: 'youngCadresPersonList', query: {theYear: this.theYear}})
      }
    },
    searchUnit (queryString, cb) {
      return this.getUnist(this, queryString, cb)
    },
    getUnist (self, queryString, cb) {
      let para = {
        deptName: queryString,
        deptCode: this.filters.sscs,
        theYear: this.theYear
      }
      self.$http
        .post(this.$http.defaults.youngAPI + `api/busUnit/queryList`, para)
        .then(function (response) {
          console.log('获取成功')
          var results = response.data.result
          let newArr = []
          results.forEach(function (item) {
            let obj = {'value': item.label}
            newArr.push(obj)
          })
          cb(newArr)
        })
        .catch(function (error) {
          console.log(error)
        })
    },
    getDics () {
      this.$http
        .get(this.$http.defaults.youngAPI + `api/young/jiben/getGenderDictList`)
        .then(response => {
          if (response.data.success) {
            this.xboptions = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.youngAPI + `api/sysDict/getByCode?code=03`)
        .then(response => {
          if (response.data.success) {
            this.shfloptions = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.youngAPI + `api/sysDict/getByCode?code=01`)
        .then(response => {
          if (response.data.success) {
            this.lyfloptions = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.youngAPI + `api/sysDict/getByCode?code=02`)
        .then(response => {
          if (response.data.success) {
            this.pysyjylxoptions = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    formatDate (str) {
      return str.slice(0, 4) + '.' + str.slice(4, 6)
    },
    toggleSelection (id) {
      this.$nextTick(() => {
        if (id) {
          let newrow = this.list.find(item => item.id === id)
          console.log(newrow)
          this.$refs.multipleTable.toggleRowSelection(newrow)
        } else {
          this.$refs.multipleTable.clearSelection()
        }
      })
    },
    handleSelectionChange (val) {
      this.ids = val.map(item => item.id)
    },
    reEnter (id) {
      this.$confirm('确认重新入库吗?', '提示', {
        type: 'success'
      }).then(() => {
        let para = {id: id}
        this.$http.post(this.$http.defaults.youngAPI + `api/busFormalPerson/updateEnter`, para).then(response => {
          if (response.data.success === true) {
            this.$message({
              message: '重新入库成功',
              type: 'success'
            })
          } else {
            console.log('重新入库失败:' + response.data.message)
            this.$message({
              message: '重新入库失败:' + response.data.message,
              type: 'error'
            })
          }
          this.getList()
        })
      }).catch(() => {
      })
    },
    del (id) {
      let ids = []
      if (id) {
        ids = [id]
      } else {
        ids = this.ids
      }
      console.log(ids)
      if (ids.length > 0) {
        this.$confirm('确认出库吗?', '提示', {
          type: 'error'
        }).then(() => {
          console.log(ids)
          console.log(this.ids)
          let para = {idList: ids}
          this.$http.post(this.$http.defaults.youngAPI + `api/busFormalPerson/updateOuter`, para).then(response => {
            if (response.data.success === true) {
              this.$message({
                message: '出库成功',
                type: 'success'
              })
            } else {
              console.log('出库失败:' + response.data.message)
              this.$message({
                message: '出库失败:' + response.data.message,
                type: 'error'
              })
            }
            this.getList()
          })
        }).catch(() => {
        })
      } else {
        this.$message({
          message: '请至少选择一条信息',
          type: 'danger'
        })
      }
    },
    dialogHide (flag) {
      this.dialogVisible = false
      if (flag) {
        this.getList()
      }
    },
    dialogHide2 () {
      this.webDataDialogVisible = false
    },
    addnew (flag, data) {
      this.readonly = false
      this.dialogtitle = '新增'
      this.personId = null
      this.dialogVisible = true
      this.timestamp = new Date().getTime()
    },
    detail (id) {
      this.readonly = true
      this.dialogtitle = '查看'
      this.personId = id
      this.dialogVisible = true
      this.timestamp = new Date().getTime()
    },
    edit (id) {
      this.readonly = false
      this.dialogtitle = '编辑'
      this.personId = id
      this.dialogVisible = true
      this.timestamp = new Date().getTime()
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList()
      }
    },
    // 查询
    search () {
      if (this.filters.zt === 0) {
        this.showCksj = false
      } else {
        this.showCksj = true
      }
      this.pageNum = 1
      this.getList()
    },
    // 排序
    sortChange: function (para) {
      if (para.order === 'ascending') {
        this.Isace = 'asc'
        this.Sortkey = para.prop
      } else if (para.order === 'descending') {
        this.Isace = 'desc'
        this.Sortkey = para.prop
      } else {
        this.Sortkey = null
        this.Isace = null
      }
      this.getList()
    },
    getList (id) {
      console.log('getlistsscsArr')
      console.log(this.sscsArr)
      let sscsArr = this.sscsArr
      if (this.inRoles('ROLE_fusizhang') && sscsArr.length === 0) {
        sscsArr = [1, 2, 3]
      }
      let para = {
        xm: this.filters.xm,
        dwmc: this.filters.dwmc,
        qsnl: this.moreShow ? this.filters.qsnl : null,
        zznl: this.moreShow ? this.filters.zznl : null,
        sfzh: this.moreShow ? this.filters.sfzh : null,
        xb: this.moreShow ? this.filters.xb : null,
        zt: this.filters.zt,
        shfl: this.moreShow ? this.filters.shfl : null,
        lyfl: this.moreShow ? this.filters.lyfl : null,
        pysyjylx: this.moreShow ? this.filters.pysyjylx : null,
        sscs: this.filters.sscs ? [this.filters.sscs] : sscsArr,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        orderField: this.Sortkey,
        orderType: this.Isace,
        isOverAge: this.filters.isOverAge,
        theYear: this.theYear
      }
      if (this.Sortkey === 'isOverAge') {
        para.orderField = 'is_over_age'
      }
      if (para.xm || para.qsnl || para.zznl || para.sfzh || para.xb || para.shfl || para.lyfl || para.pysyjylx || this.Sortkey || this.filters.zt === 1) {
        this.setOrderFlag = false
      } else {
        this.setOrderFlag = true
      }
      this.listLoading = true
      this.$http
        .post(this.$http.defaults.youngAPI + `api/busFormalPerson/queryPage`, para)
        .then(response => {
          if (response.data.success) {
            this.listLoading = false
            this.list = response.data.result.records
            this.totalnum = response.data.result.total
            this.totalPage = response.data.result.pages
            this.changeSizeFlag = false
            if (id) {
              this.toggleSelection(id)
            }
            if (response.data.result.current > response.data.result.pages && response.data.result.pages !== 0) {
              this.pageNum = response.data.result.pages
              this.getList()
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      let myheight = 315
      if (this.moreShow) {
        myheight = 377
      } else {
        myheight = 315
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - myheight
      })
    }
  },
  mounted () {
    this.theYear = this.$route.query.theYear
    this.userRoles = localStorage.getItem('Roles')
    this.getDics()
    this.checkyoungCadresRole()
    this.tableresize(this)
    window.onresize = () => {
      this.tableresize(this)
    }
  }
}
</script>
<style>
#cluereport .el-drawer__wrapper{
  width: 100%;
  height: 100%;
  position: fixed !important;
  overflow: hidden;
}
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #cluereport .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }
</style>
<style scoped>
  #cluereport .el-button{
    color:#fff !important;
  }
  #cluereport h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #cluereport .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
    padding:0;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .red-bold {
    color: red;
    font-weight: bold;
  }
</style>
